<?php

namespace app\model\training;

use app\BaseModel;
use app\model\UserModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;

/**
 * 培训讲座-任务-用户
 */
class TrainingTaskUserModel extends BaseModel
{
    protected $name = 'training_task_user';

    /**
     * 用户
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(UserModel::class,'uid')->bind([
            'user_name' => 'name',
            'avatar',
            'sex',
            'department_id',
            'phone',
            'age',
            'id_card',
            'username',
            'user_number',
            'student_status',
        ]);
    }

    /**
     * 任务讲座
     * @return BelongsTo
     */
    public function task(): BelongsTo
    {
        return $this->belongsTo(TrainingTaskModel::class,'task_id')->bind([
            'task_name'             => 'name',
            'task_type_name'        => 'type_name',
            'task_textbook_name'    => 'textbook_name',
            'task_textbook_cover'   => 'textbook_cover',
            'task_textbook_type_name'   => 'textbook_type_name',
            'task_status'           => 'status',
            'task_start_time'       => 'start_time',
            'task_end_time'         => 'end_time',
            'task_review'           => 'review',
            'task_address'          => 'address',
            'task_user_name'        => 'user_name',
            'task_role_name'        => 'role_name',
            'task_time'             => 'time',
            'task_lecturer_name'    => 'lecturer_name',
            'task_task_type'    => 'task_type',
        ]);
    }

    /**
     * 前置量表做的结果
     * @return HasMany
     */
    public function resultFront(): HasMany
    {
        return $this->hasMany(TrainingTaskUserResultModel::class,'task_user_id')->where('type','=',1);
    }

    /**
     * 课后量表做的结果
     * @return HasMany
     */
    public function resultAfter(): HasMany
    {
        return $this->hasMany(TrainingTaskUserResultModel::class,'task_user_id')->where('type','=',2);
    }


    /**
     * 结果
     * @return HasMany
     */
    public function result(): HasMany
    {
        return $this->hasMany(TrainingTaskUserResultModel::class,'task_user_id');
    }
}